//
//  NSArray+Style.m
//  WeiDianGuanJia
//
//  Created by xieyingze on 2017/4/8.
//  Copyright © 2017年 谢英泽. All rights reserved.
//

#import "NSArray+Style.h"


@implementation NSArray (Style)

- (NSArray *)arrayChangePercentNumber:(NSArray *)originalArray {
    //取出最大数
    CGFloat bigNumber = 0;
    for (NSString *str in originalArray) {
        CGFloat number = [str floatValue];
        if (bigNumber < number) {
            bigNumber = number;
        }
    }
    //载入百分比数据
    NSMutableArray *arr = [NSMutableArray array];
    for (NSString *str in originalArray) {
        CGFloat number = [str floatValue];
        if (bigNumber == 0) {
            [arr addObject:[NSNumber numberWithFloat:0.f]];
            continue;
        }
        CGFloat percent = number/bigNumber;
        [arr addObject:[NSNumber numberWithFloat:percent]];
    }
    return arr;
}

- (CGFloat)arraySumFrom:(NSArray *)originalArray {
    //载入百分比数据
    CGFloat sum = 0;
    for (NSString *str in originalArray) {
        CGFloat number = [str floatValue];
        sum = sum + number;
    }
    return sum;
}


/**
 获取最近七天的日期

 @return 日期数组
 */
+ (NSArray *)getSevenDate {
    NSMutableArray *arr = [NSMutableArray array];
    
    for (int i = 0; i < 7; i ++) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*24*60*60];
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"d日"];
        NSString *dateString = [formatter stringFromDate:date];
        [arr insertObject:dateString atIndex:0];
    }
    return arr;
}

+ (NSArray *)getSevenDateWithFormat:(NSString *)format {
    NSMutableArray *arr = [NSMutableArray array];
    
    for (int i = 0; i < 7; i ++) {
        NSDate *date = [NSDate dateWithTimeIntervalSinceNow:-i*24*60*60];
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:format];
        NSString *dateString = [formatter stringFromDate:date];
        [arr insertObject:dateString atIndex:0];
    }
    return arr;
}

+ (NSArray *)getSevenDateWithDay:(NSInteger)days {
    NSMutableArray *arr = [NSMutableArray array];
    
    for (int i = 0; i < days; i ++) {
        NSString *dateString = [NSString stringWithFormat:@"%d日",i+1];
        [arr addObject:dateString];
        //[arr insertObject:dateString atIndex:i];
    }
    return arr;
}

+ (NSArray *)getMothsOfYear {
    return @[@"1",@"2",@"3",@"4",@"5",@"6",
             @"7",@"8",@"9",@"10",@"11",@"12"];
}

@end
